package com.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class TestDemo {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        System.out.println("加载成功");

        Connection connection;
        String sql = "insert into user(username,password) values(?,?)";
        PreparedStatement ps;  //获取向数据库发送sql语句的PreparedStatement对象
        connection = DriverManager.getConnection("jdbc:mysql://106.52.210.59:3306/mydb?", "root", "78.432bCF0123qqc");
        System.out.println("连接成功");
        ps = connection.prepareStatement(sql);
        //获取输入框的内容，添加到MySQL数据库

        ps.setString(1, "0101");
        ps.setString(2, "0202");
        ps.executeUpdate();  //更新数据库

        System.out.println("插入成功");
        connection.close();
        ps.close();
    }

}
